<template>
  <div>
    <a-card :bordered="false">
      <a-steps :current="current">
        <a-step size="small" v-for="item in steps" :key="item.title" :title="item.title" />
      </a-steps>
    </a-card>
    <a-card :bordered="false" style='margin-top: 5px'>
      <step1 v-show='current===0' ref='step1'></step1>
      <step2 v-show='current===1' :ds='ds' ref='step2'></step2>
      <step3 v-show='current===2' :ds='ds' ref='step3'></step3>
      <step4 v-show='current===3' :ds='ds' ref='step4'></step4>

      <div style='margin-top: 10px;text-align: center;'>
        <a-button style='margin-right: 10px' type='primary' @click='previous' v-show='current>0'>上一步</a-button>
        <a-button style='margin-left: 10px' type='primary' @click='next' v-show='current<3'>下一步</a-button>
        <a-button style='margin-left: 10px' type='primary' @click='end' v-show='current==3'>完成</a-button>
      </div>
    </a-card>
  </div>
</template>

<script>
import Step1 from "./Step/Step1";
import Step2 from "./Step/Step2";
import Step3 from "./Step/Step3";
import Step4 from "./Step/Step4";
import EpaWeekly from "../../../myService/EpaWeekly";
export default {
  name: "epaAdd",
  components:{
    Step1,
    Step2,
    Step3,
    Step4
  },
  data(){
    return{
      current: 0,
      steps: [{title: '报表设置'},{title: '总体情况'},{title: '受理情况统计表'},{title: '重点件'},],
      ds:'',
      id:0
    }
  },
  created() {
  },
  methods:{
    next(){
      let model=this.$refs.step1.model;
      if(model.endTime==null||model.startTime==null||model.reportYear==null||model.startTime==null||model.top==null){
        this.$message.error("内容不能为空")
      }else {
        this.current++;
      }
      if(this.current===1){
        let model=this.$refs.step1.model;
        console.log("dsdsdds")
        console.log(model)
        sessionStorage.setItem('date',model.startTime);
        if(model.id==null){
          console.log(model)
          EpaWeekly.addEpaWeekly(model).then((res)=>{
            console.log(res)
            this.$refs.step1.model.id=res.result;
          })
        }else {
          EpaWeekly.updataEpaWeekly(model).then((res)=>{
            console.log(res)
          })
        }
        console.log("dsdsdsd")
        console.log(model)
        this.$refs.step2.loading(model)
      }
      if(this.current===2){
        this.$refs.step2.updata()
        this.$refs.step3.loading()
      }
      if(this.current===3){
        let model=this.$refs.step1.model;
        this.$refs.step4.loading(model);
      }
    },
    previous() {
      this.current--;
    },
    end(){
      let model=this.$refs.step1.model;
      console.log(model.id)
      this.id=model.id
      console.log(this.id)
      EpaWeekly.endEpa({id:this.id}).then((res)=>{
        console.log(res)
        if(res.result===1){
          this.$message.success("创建成功")
          this.$router.push("/epa/epa-weekly-home")
        }else{
          this.$message.error("创建失败")
        }
      })
    }
  }
}
</script>

<style scoped>

</style>